package org.dromara.wms.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseService;
import org.dromara.wms.domain.WmsOrderType;
import org.dromara.wms.service.WmsOrderTypeServiceImpl;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仓储作业类别表
 *
 * @author wenrui
 * @date 2024-03-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/orderType")
public class WmsOrderTypeController extends BaseService {

  private final WmsOrderTypeServiceImpl wmsOrderTypeService;

  /**
   * 查询仓储作业类别表列表
   */
  @SaCheckPermission("wms:orderType:list")
  @GetMapping("/list")
  public TableDataInfo<WmsOrderType> list(WmsOrderType bo, PageQuery pageQuery) {
    return wmsOrderTypeService.queryPageList(bo, pageQuery);
  }

  /**
   * 导出仓储作业类别表列表
   */
  @SaCheckPermission("wms:orderType:export")
  @Log(title = "仓储作业类别表", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(WmsOrderType bo, HttpServletResponse response) {
    List<WmsOrderType> list = wmsOrderTypeService.queryList(bo);
    ExcelUtil.exportExcel(list, "仓储作业类别表", WmsOrderType.class, response);
  }

  /**
   * 获取仓储作业类别表详细信息
   *
   * @param typeId 主键
   */
  @SaCheckPermission("wms:orderType:query")
  @GetMapping("/{typeId}")
  public R<WmsOrderType> getInfo(@NotNull(message = "主键不能为空")
                                 @PathVariable Long typeId) {
    return R.ok(wmsOrderTypeService.queryById(typeId));
  }

  /**
   * 新增仓储作业类别表
   */
  @SaCheckPermission("wms:orderType:add")
  @Log(title = "仓储作业类别表", businessType = BusinessType.INSERT)
  @RepeatSubmit()
  @PostMapping()
  public R<Void> add(@Validated(AddGroup.class) @RequestBody WmsOrderType bo) {
    return toAjax(wmsOrderTypeService.insertByBo(bo));
  }

  /**
   * 修改仓储作业类别表
   */
  @SaCheckPermission("wms:orderType:edit")
  @Log(title = "仓储作业类别表", businessType = BusinessType.UPDATE)
  @RepeatSubmit()
  @PutMapping()
  public R<Void> edit(@Validated(EditGroup.class) @RequestBody WmsOrderType bo) {
    return toAjax(wmsOrderTypeService.updateByBo(bo));
  }

  /**
   * 删除仓储作业类别表
   *
   * @param typeIds 主键串
   */
  @SaCheckPermission("wms:orderType:remove")
  @Log(title = "仓储作业类别表", businessType = BusinessType.DELETE)
  @DeleteMapping("/{typeIds}")
  public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] typeIds) {
    return toAjax(wmsOrderTypeService.deleteWithValidByIds(List.of(typeIds), true));
  }
}
